<template>
  <el-dialog title="用户登录" :visible="visible" width="500px" :before-close="beforeClose">
    <el-form :model="form" :rules="rules" size="mini" label-width="100px" ref="form">
      <el-form-item prop="chatType" label="chat模式：">
        <el-select v-model="form.chatType">
          <el-option label="创作者模式" value="chat"></el-option>
          <el-option label="程序员模式" value="code"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="accountId" label="密码：">
        <el-input v-model="form.accountId" placeholder="请输入密码"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" type="primary" @click="submit">登 录</el-button>
      <el-button size="mini" @click="closeDialog">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  name: "DialogOfAccount",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    chatType: String,
    accountId: String,
  },
  components: {},
  watch: {
    visible: {
      handler(val) {
        if (val) {
          this.init();
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      form: {
        chatType: "chat",
        accountId: "",
      },
      rules: {
        accountId: [{ required: true, message: "请输入密码！" }],
      },
    };
  },
  methods: {
    init() {
      this.resetForm();
    },
    resetForm() {
      this.$refs.form && this.$refs.form.resetFields();
      if (this.chatType) this.form.chatType = this.chatType;
      if (this.accountId) this.form.accountId = this.accountId;
    },
    refreshData() {
      this.$emit("success", this.form);
    },
    beforeClose(done) {
      this.closeDialog();
      done();
    },
    closeDialog() {
      this.$emit("closeDialog", "dialogOfAccount");
    },
    submit() {
      this.refreshData();
      this.closeDialog();
    },
  },
};
</script>
<style lang="scss" scoped></style>
